	/**
	 * google: UP5vh5NZ8hT3
	 * MUNIRUL HODA
	 * CS 340 PROJECT 1 (SCARECROW-ROBOT FACTORY)
	 */

public class Scarecrow_Factory {
	
	public static long time = System.currentTimeMillis();
	static HandsManufacturer handsManThread;
	static LegsManufacturer legsManThread;
	static TorsoManufacturer torsoManThread;
	static HeadManufacturer headManThread;
	static BroomManufacturer broomManThread;

	static Factory factoryThread;
	
	public static void main(String[] args) {
		handsManThread = new HandsManufacturer(1);
		legsManThread = new LegsManufacturer(1);
		torsoManThread = new TorsoManufacturer(1);
		headManThread = new HeadManufacturer(1);
		broomManThread = new BroomManufacturer(1);

		factoryThread = new Factory(1);
		
		handsManThread.start();
		legsManThread.start();
		torsoManThread.start();
		headManThread.start();
		broomManThread.start();

		factoryThread.start();
	}

	public static void sendTruckBack(Truck t) {
		if (t.partType == "BROOM")
			broomManThread.truckReturns(t);
		else if (t.partType == "HEAD")
			headManThread.truckReturns(t);
		else if (t.partType == "TORSO")
			torsoManThread.truckReturns(t);
		else if (t.partType == "HAND")
			handsManThread.truckReturns(t);
		else if (t.partType == "LEG")
			legsManThread.truckReturns(t);
	}
	
	public static Manufacturer[] sortManufacturers(int noOfB, int noOfHe, int noOfT, int noOfHa, int noOfL) {
		Manufacturer[] manufacturerByNeed = new Manufacturer[5];
		int indexOfMax;
		int[] noOfParts = {noOfB, noOfHe, noOfT, noOfHa, noOfL};
		
		for (int i=4; i>=0; i--){
			indexOfMax = indexOfMax(noOfParts);
			switch (indexOfMax){
				case 0:
					manufacturerByNeed[i] = broomManThread;
					noOfParts[0] = -1;
					break;
				case 1:
					manufacturerByNeed[i] = headManThread;
					noOfParts[1] = -1;
					break;
				case 2:
					manufacturerByNeed[i] = torsoManThread;
					noOfParts[2] = -1;
					break;
				case 3:
					manufacturerByNeed[i] = handsManThread;
					noOfParts[3] = -1;
					break;
				case 4:
					manufacturerByNeed[i] = legsManThread;
					noOfParts[4] = -1;
					break;
//				default:
					
			}
		}
				
		return manufacturerByNeed;
	}
	
	public static int indexOfMax(int[] t) {
	    int maximum = t[0];   
	    int maxIndex = 0;
	    for (int i=1; i<t.length; i++) {
	        if (t[i] > maximum) {
	            maximum = t[i];   
	            maxIndex = i;
	        }
	    }
	    return maxIndex;
	}

}

/*                                                   YET TO DO
 * At the end ofOPERATION_TIME report the total number; scw, parts
 * 
 * You should keep the concurrency of the threads as high as possible. using the sleep
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 */
